* Replication Code: Did the Budapest Convention Deter Cybercrime? An Event Study Using a Panel of Countries
* Authors: Humza Khan and Pengfei Zhang
* Data: DDOS 2004-2008

* Install programs
ssc install reghdfe
ssc install event_plot
ssc install did_imputation
ssc install csdid
ssc install drdid
ssc install ivreg2
ssc install avar
ssc install eventstudyinteract
ssc install did_multiplegt

* Import data 

*converts strings (characters/text) to numeric
destring, replace
 
*1 OLS regression
regress attack treatment

*2 country fixed effect
xtreg attack treatment, fe

* 3 TWFE
reghdfe attack treatment, absorb(country_num tq) cluster(country_num)

* 4 TWFE plus controls
reghdfe attack treatment gdp internet education, absorb(country_num tq) cluster(country_num)

*Drop observations based on time window
drop if timeToTreat < -10
drop if timeToTreat > 10
 
* leads/lags
forvalues l = 0/10 {  
    gen L`l'event = timeToTreat == `l'
} 
forvalues l = 1/10 {   
    gen F`l'event = timeToTreat == -`l' 
} 
drop F1event

*Dynamic Regression  
reghdfe attack F*event L*event, absorb(country_num tq) cluster(country_num)
estimates store ols  

* Event plot ols
event_plot ols, ///
    stub_lag(L#event) stub_lead(F#event) plottype(scatter) ciplottype(rcap) ///
    graph_opt(ytitle("Estimated Change in DDoS Attacks") ylabel(, labsize(small)) xlabel(-10(1)10, labsize(small)) xtitle("Quarters Before and After Ratification") ///
        legend(off) ///
        xline(-1, lcolor(gs13) lpattern(dash)) yline(0, lcolor(gs13)) graphregion(color(white)) bgcolor(white) ylabel(, angle(horizontal)) ///
    ) ///
    lag_opt1(msymbol(O) color(black)) lag_ci_opt1(color(black))	



